//package com.zdp.contentcenter.service.content;
//
//import com.zdp.contentcenter.dao.content.ShareMapper;
//import com.zdp.contentcenter.domain.dto.content.ShareAuditDTO;
//import com.zdp.contentcenter.domain.dto.content.ShareDTO;
//import com.zdp.contentcenter.domain.dto.message.UserAddBonusMsgDTO;
//import com.zdp.contentcenter.domain.dto.user.UserDTO;
//import com.zdp.contentcenter.domain.entity.content.Share;
//import com.zdp.contentcenter.domain.enums.AuditStatusEnum;
//import com.zdp.contentcenter.feignclient.UserCenterFeignClient;
//import lombok.RequiredArgsConstructor;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.apache.rocketmq.spring.support.RocketMQHeaders;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.Objects;
//import java.util.UUID;
//
///**
// * @author sesshomaru
// * @date 2020/9/17 0:18
// *
// * 一般的RocketMQ消息投递
// */
//@RequiredArgsConstructor(onConstructor = @_(@Autowired))
////@Service
//public class ShareService1 {
//
//    private final ShareMapper shareMapper;
//
//    private final UserCenterFeignClient userCenterFeignClient;
//
//    private final DiscoveryClient discoveryClient;
//
//    private final RocketMQTemplate rocketMQTemplate;
//
//    public ShareDTO findById(Integer id) {
//        // 获取分享详情
//        Share share = this.shareMapper.selectByPrimaryKey(id);
//        // 发布人id
//        Integer userId = share.getUserId();
//
//        UserDTO userDTO = userCenterFeignClient.findById(userId);
//
//        ShareDTO shareDTO = new ShareDTO();
//        BeanUtils.copyProperties(share, shareDTO);
//        shareDTO.setWxNickName(userDTO.getWxNickname());
//
//        return shareDTO;
//    }
//
//
//    public Share auditById(Integer id, ShareAuditDTO shareAuditDTO) {
//        // 1.查询share是否存在, 不存在或者当前的审核状态不是待审核 则抛出异常
//        Share share = this.shareMapper.selectByPrimaryKey(id);
//        if (share == null) {
//            throw new IllegalArgumentException("参数非法! 该分享不存在!");
//        }
//        if (!Objects.equals("NOT_YET", share.getAuditStatus())) {
//            throw new IllegalArgumentException("参数非法! 该分享已审核通过或者审核不通过");
//        }
//
//        // 2.审核资源 将状态设为审核通过或者不通过
//        share.setAuditStatus(shareAuditDTO.getAuditStatusEnum().toString());
//        this.shareMapper.updateByPrimaryKey(share);
//        // 3.如果是PASS(审核通过)就为发布人添加积分
//        // 异步的去积分
//        //userCenterFeignClient.addBonus(id, 500);
//        // 参数1是topic 2是消息体
//        // add-bonus就是RocketMQ的topic
//        this.rocketMQTemplate.convertAndSend("add-bonus",
//                UserAddBonusMsgDTO.builder()
//                        .userId(share.getUserId())
//                        .bonus(50)
//                        .build());
//        return share;
//    }
//}
